package com.witdata.common.domain.vo;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.witdata.common.domain.enums.ActiveStatus;
import com.witdata.common.domain.enums.classroom.SubjectsType;
import com.witdata.common.serializer.ToLongDeSerializer;
import com.witdata.mysql.domain.entity.TCourseSubjects;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class CourseSubjectsVo {

    @JsonSerialize(using = ToStringSerializer.class)
    @JsonDeserialize(using = ToLongDeSerializer.class)
    private Long id;
    
    private String courseId;

    private String subjectId;

    private SubjectsType type;

    private LocalDateTime startTime;

    private LocalDateTime endTime;

    private ActiveStatus status;

    public CourseSubjectsVo(TCourseSubjects tCourseSubjects) {
        this.id = tCourseSubjects.getId();
        this.courseId = tCourseSubjects.getCourseId().toString();
        this.subjectId = tCourseSubjects.getSubjectId().toString();
        this.type = SubjectsType.values()[tCourseSubjects.getType()];
        this.startTime = tCourseSubjects.getStartTime();
        this.endTime = tCourseSubjects.getEndTime();
        this.status = tCourseSubjects.getStatus()?ActiveStatus.ACTIVE:ActiveStatus.INACTIVE;
    }

    public TCourseSubjects toTCourseSubjects() {
        return TCourseSubjects.builder()
            .id(id)
            .courseId(Long.parseLong(courseId))
            .subjectId(Long.parseLong(subjectId))
            .type(type.ordinal())
            .startTime(startTime)
            .endTime(endTime)
            .status(status.equals(ActiveStatus.ACTIVE))
            .build();
    }
}
